package com.zzu.service;

import com.zzu.dao.IManagerDao;
import com.zzu.dao.IStudentDao;
import com.zzu.model.Manager;
import com.zzu.model.SC;
import com.zzu.model.Student;
import com.zzu.utils.MyBatisUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.List;


public class StudentService {

    //获得学生账号
    public Student findStudent(String id, String password){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
        return studentDao.findStudent(id,password);
    }

    //从视图中查看全部学生信息
    public List<Student> findAllStudents(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
        return studentDao.findAllStudents();
    }

    //删除学生操作
    public boolean deleteStudent(String id){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
        boolean flag = studentDao.deleteStudent(id);
        sqlSession.commit();
        return flag;
    }

    //增加学生操作
    public boolean addStudent(Student student){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
        boolean flag = studentDao.addStudent(student);
        sqlSession.commit();
        return flag;
    }

    //通过id查找学生
    public Student findStudentById(String Sid)
    {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        IStudentDao mapper = sqlSession.getMapper(IStudentDao.class);
        return mapper.findStudentById(Sid);
    }

    //查找学生选修课程的成绩
    public List<SC> findAllCourses(String sId){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        IStudentDao mapper = sqlSession.getMapper(IStudentDao.class);
        return mapper.findAllCourses(sId);
    }
    @Test
    public void test()
    {
        System.out.println(findAllCourses("201600000000"));
    }

}
